home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Includes / UView.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  54.7 KB  |  1,468 lines  |  [TEXT/MPS ]

  1. // UView.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4.  
  5. #ifndef __UVIEW__
  6. #define __UVIEW__
  7.  
  8. // MacApp
  9.  
  10. #ifndef __UADORNERS__
  11. #include "UAdorners.h"
  12. #endif
  13.  
  14. #ifndef __UCOMMANDHANDLER__
  15. #include "UCommandHandler.h"
  16. #endif
  17.  
  18. #ifndef __UGEOMETRY__
  19. #include "UGeometry.h"
  20. #endif
  21.  
  22. #ifndef __UITERATOR__
  23. #include "UIterator.h"
  24. #endif
  25.  
  26. // Toolbox
  27.  
  28. #ifndef __BALLOONS__
  29. #include <Balloons.h>
  30. #endif
  31.  
  32. #if qDrag
  33. #    ifndef __DRAG__
  34. #    include <Drag.h>
  35. #    endif
  36. #endif
  37.  
  38. #if qGXViews || qGXPrinting    
  39. #    ifndef __GXTYPES__
  40. #    include <GXTypes.h>
  41. #    endif
  42. #endif
  43.  
  44. //----------------------------------------------------------------------------------------
  45. // Forward and external class declarations. 
  46. //----------------------------------------------------------------------------------------
  47.  
  48. class CAEDesc;
  49. class CDragItemIterator;
  50. class TAdorner;
  51. class TAdornerList;
  52. class TDesignator;
  53. class TDocument;
  54. class TDragItem;
  55. class TDrawingEnvironment;
  56. class TPrintHandler;
  57. class TScroller;
  58. class TToolboxEvent;
  59. class TWindow;
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // MouseDownType
  63. //----------------------------------------------------------------------------------------
  64.  
  65. enum EMouseDownType 
  66. {
  67.     //kDragOnly,                    // (never used)
  68.     kDragOrClick,                // !isFirstClick
  69.     kFirstClick_dragOnly,        // isFirstClick        !windowDoesFirstClick
  70.     kFirstClick_dragOrClick        // isFirstClick        windowDoesFirstClick
  71. };
  72.  
  73. //----------------------------------------------------------------------------------------
  74. // Constants
  75. //----------------------------------------------------------------------------------------
  76. const unsigned char kFrame = adnLineTop | adnLineLeft | adnLineBottom | adnLineRight;
  77.                                                 // Defines that a view be completely framed.
  78.  
  79. const Boolean kImmediateSuperView = TRUE;        // Used with GetScroller to return only the
  80.                                                 // scroller of the immediate superview
  81. const Boolean kAnySuperView = FALSE;            // Used with GetScroller to return scroller
  82.                                                 // in the super view chain
  83. const Boolean kInsertSubViewFirst = FALSE;        // Use to insert subviews at the front of
  84.                                                 // the list rather than the end (default). 
  85.  
  86. //----------------------------------------------------------------------------------------
  87. // SizeDeterminer: Tells how a view's size is to be determined; specified separately in
  88. // each dimension.
  89. //----------------------------------------------------------------------------------------
  90.  
  91. enum SizeDeterminer
  92. {
  93.     sizeSuperView,                                // View is the same size as its superview
  94.  
  95.     sizeRelSuperView,                            // View size is relative to the
  96.                                                 // superview's size
  97.  
  98.     sizePage,                                    // View to be the size of one page
  99.  
  100.     sizeFillPages,                                // View to grow upward to fill an exact
  101.                                                 // number of pages
  102.  
  103.     sizeVariable,                                // View size fluctuates according to
  104.                                                 // app-specific criteria
  105.  
  106.     sizeFixed
  107. };
  108.  
  109. //----------------------------------------------------------------------------------------
  110. // ViewPortInfo: Set by GetFocus; used by SetFocus. GetFocus/ SetFocus are used to save and
  111. // restore the focus behind MacApp's back.
  112. //----------------------------------------------------------------------------------------
  113.  
  114. struct ViewPortInfo
  115. {
  116.     CPoint org;
  117.     GrafPtr port;
  118.     RgnHandle clip;
  119.     Boolean isValid;                            // true if FocusRec is valid
  120. };
  121.  
  122.  
  123. //----------------------------------------------------------------------------------------
  124. // FocusRec
  125. //----------------------------------------------------------------------------------------
  126.  
  127. struct FocusRec
  128. {
  129.     ViewPortInfo itsViewPortInfo;
  130.     Boolean printing;
  131.     Boolean drawingPictScrap;
  132.     TView* drawingPictScrapView;
  133.     TView* focusedView;
  134. };
  135.  
  136.  
  137. //----------------------------------------------------------------------------------------
  138. // TView: Renders an image of a document or other data, and identifies mouse-clicked
  139. // objects.
  140. //----------------------------------------------------------------------------------------
  141.  
  142. class TView : public TCommandHandler
  143. {
  144.     MA_DECLARE_CLASS;
  145.     
  146.   public:
  147.     //------------------------------------------------------------------------------------
  148.     // Creation/ Destruction Methods
  149.     //------------------------------------------------------------------------------------
  150.  
  151.     TView();
  152.         // Constructor
  153.         
  154.     void IView(TDocument* itsDocument,
  155.                TView* itsSuperView,
  156.                const VPoint& itsLocation,
  157.                const VPoint& itsSize,
  158.                SizeDeterminer itsHSizeDet,
  159.                SizeDeterminer itsVSizeDet);
  160.         // Initializes a view procedurally.
  161.  
  162.     void HandlePostCreate(TDocument* itsDocument);
  163.         // Post-order traversal calling DoPostCreate
  164.     
  165.     virtual void DoPostCreate(TDocument* itsDocument);
  166.         // Called in a post-order traversal of a newly-created view hierarchy
  167.         
  168.     virtual TObject* Clone();
  169.         // Calls Inherited::Clone and then clones owned objects.
  170.  
  171.     virtual ~TView();
  172.         // Frees its subviews, then if its superview is not NULL removes itself from the
  173.         // superviews list of subviews and if its document is not NULL removes itself from
  174.         // the documents list of views. If it has a print handler then it frees it, then
  175.         // calls Inherited::Free. Frees its fAdorners list.
  176.  
  177.     virtual void FreeFromClipboard();
  178.         // If its document is not NULL then calls the document's FreeFromClipboard method,
  179.         // otherwise calls Free.
  180.  
  181.  
  182.     //------------------------------------------------------------------------------------
  183.     // Standard signature support.
  184.     //------------------------------------------------------------------------------------
  185.  
  186.     virtual IDType GetStandardSignature();    // override 
  187.         // Returns this class's standard signature.
  188.  
  189.     //------------------------------------------------------------------------------------
  190.     // Stream I/O protocol support.
  191.     //------------------------------------------------------------------------------------
  192.  
  193.     virtual void ReadFrom(TStream* aStream);
  194.     virtual void ReadFields(TStream* aStream);
  195.     virtual void ReadSubViews(TStream* aStream);
  196.     
  197.     virtual void WriteTo(TStream* aStream);
  198.     virtual void WriteFields(TStream* aStream);
  199.     virtual void WriteSubViews(TStream* aStream);
  200.  
  201.  
  202.     //------------------------------------------------------------------------------------
  203.     // Coordinate Conversion Methods
  204.     //------------------------------------------------------------------------------------
  205.  
  206.     VPoint QDToViewPt(CPoint qdPoint);
  207.     inline void QDToViewPt(CPoint qdPoint, VPoint& viewPt)
  208.     { viewPt = QDToViewPt(qdPoint); }
  209.         // Convert a QuickDraw point to a view point.
  210.  
  211.     VRect QDToViewRect(const CRect& qdRect);
  212.     inline void QDToViewRect(const CRect& qdRect, VRect& viewRect)
  213.     { viewRect = QDToViewRect(qdRect); }
  214.         // Convert a QuickDraw CRect to a view rect.
  215.  
  216.     CPoint ViewToQDPt(const VPoint& viewPt);
  217.         // Convert a view point to a QuickDraw point.
  218.  
  219.     CRect ViewToQDRect(const VRect& viewRect);
  220.     inline void ViewToQDRect(const VRect& viewRect, CRect& qdRect)
  221.     { qdRect = ViewToQDRect(viewRect); }
  222.         // Convert a view rect to a QuickDraw CRect.
  223.  
  224.     VPoint GetLocalOffsetInSuper() const;
  225.     inline void GetLocalOffsetInSuper(VPoint& localOffsetInSuper) const
  226.     { localOffsetInSuper = GetLocalOffsetInSuper(); }
  227.         // Returns the location of the origin for this view coordinate systemin the
  228.         // superview's coordinate system
  229.  
  230.     virtual void SetLocalOrigin(const VPoint& newOrigin, Boolean redraw);
  231.         // Sets the origin of the view's local coordinate system. Redraws if requested.
  232.  
  233.     void LocalToSuper(VPoint& thePoint) const;
  234.         // Given a point in local view coordinates, returns the same point in its
  235.         // superview's coordinate system.
  236.  
  237.     void LocalToSuperVRect(VRect& viewRect) const;
  238.         // Given a rect in local view coordinates, returns the same rect in its
  239.         // superview's coordinate system.
  240.  
  241.     void LocalToSuperRegion(RgnHandle theRgn);
  242.         // Given a region in local view coordinates, returns the same region in its
  243.         // superview's coordinate system.
  244.         
  245.     void LocalToGlobalRegion(RgnHandle theRgn);
  246.         // Given a region in local view coordinates, returns the same region in
  247.         // global screen coordinates.
  248.         
  249.     void LocalToWindowRegion(RgnHandle theRgn);
  250.         // Given a region in local view coordinates, returns the same region in its
  251.         // window's coordinate system.
  252.  
  253.     void LocalToWindow(VPoint& thePoint) const;
  254.         // Given a point in local view coordinates, returns the same point in its window's
  255.         // (or most super superview's) coordinate system.
  256.  
  257.     void SuperToLocal(VPoint& thePoint) const;
  258.         // Given a point in superview coordinates, returns the same point in the view's
  259.         // own coordinate system.
  260.  
  261.     void SuperToLocalVRect(VRect& viewRect) const;
  262.         // Given a rect in superview coordinates, returns the same rect in the view's own
  263.         // coordinate system.
  264.  
  265.     void SuperToLocalRegion(RgnHandle theRgn);
  266.         // Given a region in superview coordinates, returns the same region inthe view's
  267.         // own coordinate system.
  268.  
  269.     void WindowToLocal(VPoint& thePoint) const;
  270.         // Given a point in window (or most super superview) coordinates, returns the same
  271.         // point in the view's own coordinate system.
  272.  
  273.  
  274.     //------------------------------------------------------------------------------------
  275.     // SubView Management Methods
  276.     //------------------------------------------------------------------------------------
  277.  
  278.     void InsertSubView(TView* theSubView, Boolean last = TRUE);
  279.         // Add 'theSubView' to our list of subviews. By default adds to end of list
  280.         // (in drawing order). To add to the front of the list, pass kInsertSubViewFirst. 
  281.         // Just does list manipulation doesn't do any sub/superview notification
  282.  
  283.     void DeleteSubView(TView* theSubView);
  284.         // Remove 'theSubView' from our list of subviews.
  285.         // Just does list manipulation doesn't do any sub/superview notification
  286.  
  287.     void AddSubView(TView* theSubView);
  288.         // Add 'theSubView' to our list of subviews.
  289.  
  290.     void RemoveSubView(TView* theSubView);
  291.         // Remove 'theSubView' from our list of subviews.
  292.  
  293.     void MakeFirstSubView(TView* theSubView);
  294.         // Make 'theSubView ' the first subview in our list.
  295.  
  296.     void MakeLastSubView(TView* theSubView);
  297.         // Make 'theSubView' the last subview in our list.
  298.  
  299.     short CountSubViews() const;
  300.         // Return the number of subviews in our view.
  301.  
  302.     inline Boolean HasSubViews() const
  303.     { return (fSubView != NULL); }
  304.         // True if this view has subviews.
  305.  
  306.     inline TView* FirstSubView() const
  307.     { return fSubView; }
  308.         // Return the first subview in our list (NULL if none).
  309.  
  310.     TView* FindSubView(IDType itsIdentifier) const;
  311.         // Find subview with identifier 'itsIdentifier' in our list of subviews.
  312.  
  313.     Boolean ContainsSubView(TView* aView) const;
  314.         // Returns true if aView is in the view hierarchy with this view as root
  315.  
  316.         
  317.     //------------------------------------------------------------------------------------
  318.     // Open/ Close/Activate Methods
  319.     //------------------------------------------------------------------------------------
  320.  
  321.     virtual void Activate(Boolean entering);
  322.         // Focuses and then highlights any current selection before calling all its
  323.         // subviews to activate themselves.
  324.  
  325.     virtual void Open();
  326.         // Calls each of its subviews to Open themselves.
  327.  
  328.     virtual void Close();
  329.         // Commits the last command before calling each of its subviews to Close
  330.         // themselves.
  331.  
  332.     virtual void BeInDocument(TDocument* itsDocument);
  333.         // If 'itsDocument' is not NULL then sets its fDocument to itsDocument and
  334.         // add itself to the documents viewlist.
  335.  
  336.     virtual void BeInScroller(TScroller* itsScroller);
  337.         // If 'itsScroller' is not NULL then sets its scroll limits to its fSize.
  338.  
  339.     virtual void BeInPort(GrafPtr itsPort);
  340.         // If its print handler is not NULL, calls DoCheckPrinter. Then calls each of its
  341.         // subviews to BeInPort.
  342.  
  343.     virtual void ShowReverted();
  344.         // First calls AdjustSize before forcing a redraw of the view, then call
  345.         // ShowReverted for each of its subviews.
  346.  
  347.  
  348.     //------------------------------------------------------------------------------------
  349.     // Frame (Location and Size) Methods
  350.     //------------------------------------------------------------------------------------
  351.  
  352.     virtual void SetFrame(const VRect& newFrame, Boolean invalidate);
  353.         //  sets our frame to newFrame, invalidating if 'invalidate' is true. 
  354.  
  355.     virtual void InvalidateFrameDifference(const VRect& oldFrame, const VRect& newFrame);
  356.         // Invalidates the difference between the old and new frames, unless the location has
  357.         // changed, in which case the union of the two frames is invalidated.
  358.         
  359.     virtual void NotifyAdornersOfFrameChange(const VRect& oldFrame,
  360.                                              const VRect& newFrame,
  361.                                              Boolean invalidate);
  362.         // Iterates over this view's adorners, calling ViewChangedFrame. Called by TView::SetFrame
  363.  
  364.     virtual void NotifySubViewsOfFrameChange(const VRect& oldFrame,
  365.                                              const VRect& newFrame,
  366.                                              Boolean invalidate);
  367.         // Iterates over this view's subviews, calling SuperViewChangedFrame. Called by TView::SetFrame
  368.  
  369.     virtual void Locate(const VPoint& newLoc, Boolean invalidate);
  370.         //  Convenience routine. Sets the frame to newLoc. Don't override it since
  371.         //  MacApp usually calls SetFrame instead. 
  372.  
  373.     virtual void Resize(const VPoint& newSize, Boolean invalidate);
  374.         //  Convenience routine. Sizes the frame to newSize. Don't override it since
  375.         // MacApp usually calls SetFrame instead. 
  376.  
  377.     virtual void AdjustFrame();
  378.         // Calls ComputeFrame, if the size has changed resizes itself and then calls
  379.         // DoPagination so that any page breaks can be recalculated.
  380.  
  381.     virtual VRect CalcMinFrame();
  382.         // Calculate the minimum size of this.
  383.  
  384.     virtual void ComputeFrame(VRect& newFrame);
  385.         // Called by MacAppto get the size of the view computed.
  386.  
  387.     virtual void SuperViewChangedFrame(const VRect& oldFrame,
  388.                                        const VRect& newFrame,
  389.                                        Boolean invalidate);
  390.         // Called when our superview changes frame.
  391.  
  392.     virtual void SubViewChangedFrame(TView* theSubView,
  393.                                      const VRect& oldFrame,
  394.                                      const VRect& newFrame,
  395.                                      Boolean invalidate);
  396.         // Called when one of our subviews changes frame.
  397.  
  398.  
  399.     //------------------------------------------------------------------------------------
  400.     // Focusing Methods
  401.     //------------------------------------------------------------------------------------
  402.  
  403.     virtual Boolean Focus();
  404.         // Attempts to set up the drawing environment for this view. That consists of
  405.         // port, origin, gLongOffset and clipping. Returns false if not able to focus. One
  406.         // reason focus could fail is if no superview is able to supply a port (ie not in
  407.         // a window and not printing or drawing pict scrap). Focus will return true,
  408.         // however, if the drawing environment can be setup but none of the view is
  409.         // currently visible due to clipping or scrolling by a superview. This lets you
  410.         // assemble view hierarchies and manipulate views without showing them to the
  411.         // user, but requires that you test IsVisible if you MUST know if the view is in
  412.         // fact visible. (MacApp will never ask a view to draw unless it is visible)
  413.  
  414.     virtual Boolean FocusOnSuperView();
  415.         // Focuses on our superview.
  416.  
  417.     inline void InvalidateFocus()
  418.     { gFocusedView = NULL; }
  419.         // Indicates that the view's focus is no longer valid and must be recomputed.
  420.  
  421.     inline Boolean IsFocused() const
  422.     { return gFocusedView == this; }
  423.         // Check to see if we are currently focused.
  424.  
  425.     void ClipFurtherTo(RgnHandle rRgn, CPoint deltaOrg);
  426.         // Set clipping to: (<current clipping> INTERSECT r) OFFSET-BY deltaOrg.
  427.  
  428.     void OffsetAndClipFurtherTo(RgnHandle rRgn, CPoint deltaOrg);
  429.         // Set clipping to: OFFSET-BY deltaOrg and (<current clipping>
  430.         // INTERSECT r).
  431.  
  432. #if qDebug
  433.     void AssumeFocused() const;
  434.         // Causes a ProgramBreak if the focused view isn't this.
  435. #endif
  436.  
  437.     void InvalidateCoordinates();
  438.         // Indicates that the view's computed offsets are no longer valid and must be
  439.         // recomputed.  Calls InvalidateCoordinates for all subviews.
  440.  
  441.     virtual void UpdateCoordinates();
  442.         // Called If a coordinate related field must be retrieved and the coordinates
  443.         // are invalid.
  444.  
  445.     VRect GetVisibleExtent();
  446.         // Retrieves the fVisibleExtent, calls UpdateCoordinates if necessary.
  447.  
  448.     CPoint GetQDOrigin();
  449.         // Retrieves the fQDOrigin, calls UpdateCoordinates if necessary.
  450.  
  451.     VPoint GetViewToQDOffset();
  452.         // Retrieves the fViewToQDOffset, calls UpdateCoordinates if necessary.
  453.  
  454.     
  455.     //------------------------------------------------------------------------------------
  456.     // Adornment Methods
  457.     //------------------------------------------------------------------------------------
  458.  
  459.     virtual TAdornerList* MakeAdornerList();
  460.     
  461.     void AddAdorner(TAdorner* anAdorner,
  462.                     AdornPriority itsPriority,
  463.                     Boolean invalidate);
  464.         // adds an adorner to the view; invalidates the adorner if "invalidate" is true
  465.  
  466.     void DeleteAdorner(TAdorner* anAdorner, Boolean invalidate);
  467.         // removes an adorner from the view; invalidates the adorner if "invalidate" is
  468.         // true
  469.  
  470.     void DeleteAdornerByID(IDType itsID, Boolean invalidate);
  471.         // removes an adorner from the view; invalidates the adorner if "invalidate" is
  472.         // true
  473.  
  474.     TAdorner* AdornerAt(ArrayIndex i) const;
  475.         // Returns the i'th adorner in the list
  476.  
  477.     TAdorner* AdornerWithID(IDType itsID) const;
  478.         // Returns the first adorner with the specified ID
  479.         
  480.     virtual void Dim();
  481.         // dims the current image in the view
  482.  
  483.     virtual void GetAdornExtent(VRect& itsAdornExtent);
  484.         // returns the adorn extent for adorning this view
  485.  
  486.     virtual void Hilite();
  487.         // hilites the current image in the view by inverting its extent
  488.  
  489.     //------------------------------------------------------------------------------------
  490.     // Drawing Methods
  491.     //------------------------------------------------------------------------------------
  492.  
  493.     virtual TDrawingEnvironment* DoMakeNewDrawingEnvironment();
  494.         // Create a new drawing environment
  495.  
  496.     void CreateDrawingEnvironment();
  497.         // Creates a new drawing environment, if none exists.
  498.         
  499.     void SetDrawingEnvironment(TDrawingEnvironment* itsDrawingEnvironment,
  500.                                Boolean invalidate);
  501.         // Frees the old drawing environment and stores the new one.
  502.         
  503.     inline TDrawingEnvironment* GetDrawingEnvironment() const
  504.     { return fDrawingEnvironment; }
  505.         // Returns this view's drawing environment object, which may be NULL.
  506.     
  507.     void PrepareForDrawing();
  508.         // A possible "hook" for doing offscreen drawing. 
  509.         // If the view has an fDrawingEnvironment, calls its Prepare method.
  510.         // Calls SetupDrawingEnvironment.
  511.  
  512.     void SetupDrawingEnvironment();
  513.         // If the view has an fDrawingEnvironment, calls its Setup method.
  514.         // Otherwise calls PenNormal.
  515.  
  516.     void CompleteDrawing();
  517.         // If the view has an fDrawingEnvironment, calls its Complete method.
  518.         // A possible "hook" for doing offscreen drawing
  519.  
  520.     virtual void UpdateSelection(const VPoint& /* theMouse */, 
  521.                                  TToolboxEvent * /* event */);
  522.         // Called prior to DoMouseDown and WillDrag. Provides an opportunity
  523.         // to update selection before being asked to drag or handle a mouse
  524.         // down.
  525.         
  526.     virtual void DoHighlightSelection(HLState fromHL, HLState toHL);
  527.         // Currently does nothing. Must be overridden.
  528.  
  529.     HLState GetCurrentHL();
  530.         // Returns fActiveHL if the view is active, otherwise fInActiveHL.
  531.  
  532.     virtual void Draw(const VRect& area);
  533.         // Currently does nothing. Must be overridden.
  534.  
  535.     void HandleDraw(const VRect& area);
  536.         // Causes the area of the views contents to be drawn and that of any of its subviews.
  537.  
  538.     void DrawContents();
  539.         // Causes the views contents to be drawn and that of any of its subviews.
  540.  
  541.     void DrawAdorners(const VRect& area);
  542.         //    Asks each adorner in the list of adorners to draw
  543.  
  544.     void HighlightAdorners(const VRect& area,
  545.                            HLState fromHL,
  546.                            HLState toHL);
  547.         // Calls each adorner's DoHighlightSelection method
  548.         
  549.     virtual TDesignator* GetUserSelection();
  550.         // Returns the designator for the user selection (if any).Defaults to returning
  551.         // the user selection of the document (if any)
  552.  
  553.     virtual void SetUserSelection(TDesignator* newSelection);
  554.         // Sets the designator for the user selection (if any). Defaults to setting the
  555.         // user selection of the document (if any)
  556.  
  557.     virtual void UserSelectionChanged(TView* changedView);
  558.         // Call this whenever the user's selection changes. Defaults to calling the
  559.         // UserSelectionChanged method of the document (if any).
  560.  
  561.     virtual void ScrollSelectionIntoView(Boolean redraw);    
  562.         // Scroll the selection into view.
  563.  
  564.     virtual Boolean HasPendingUpdate();
  565.         // Returns true if there is a pending update event for this view, false if not.
  566.  
  567.     virtual void Update();
  568.         // If its window is not NULL then does an update by calling DrawContents.
  569.     
  570.  
  571.     //------------------------------------------------------------------------------------
  572.     // Validation/ Invalidation Methods
  573.     //------------------------------------------------------------------------------------
  574.  
  575.     virtual void ForceRedraw();
  576.         // Invalidates the entire view forcing a redraw.
  577.  
  578.     void InvalidateVRect(const VRect& badVRect);
  579.         // Invalidates a QuickDraw CRect by calling InvalidateRect.
  580.  
  581.     void InvalidateRect(const CRect& badRect);
  582.         // Invalidates a View CRect by calling InvalidateRegion.
  583.  
  584.     void InvalidateRegion(const RgnHandle badRgn);
  585.         // Intersects badRgn with the visible extent then calls DoInvalidateRegion with the
  586.         // result. We can only call InvalidRgn on a grafPort belonging to a window, if
  587.         // your code calls InvalidRgn on a non-window grafPort, it will die miserably. So
  588.         // views forward up their superview chain until they reach a view which overrides
  589.         // DoInvalidateRegion (usually a window) which then makes the actual InvalidRgn call
  590.  
  591.     virtual void DoInvalidateRegion(const RgnHandle badRgn);
  592.         // Invalidates a Region by passing it to the superview
  593.  
  594.     void ValidateVRect(const VRect& goodVRect);
  595.         // Validates a view rect by calling ValidateRect.
  596.  
  597.     void ValidateRect(const CRect& goodRect);
  598.         // Validates a QuickDraw rect by calling ValidateRegion.
  599.  
  600.     void ValidateRegion(const RgnHandle goodRgn);
  601.         // Intersects goodRgn with the visible extent then calls DoValidateRegion with the
  602.         // result. We can only call ValidRgn on a grafPort belonging to a window, if your
  603.         // code calls ValidRgn on a non-window grafPort, it will die miserably. So views
  604.         // forward up their superview chain until they reach a view which overrides
  605.         // DoValidateRegion (usually a window) which then makes the actual ValidRgn call
  606.  
  607.     virtual void DoValidateRegion(const RgnHandle goodRgn);
  608.         // Validates a Region by passing it to the superview
  609.  
  610.     virtual void RevealRect(const VRect& rectToReveal,
  611.                             const VPoint& minToSee,
  612.                             Boolean redraw);
  613.         // Scrolls a rect into view, with 'minToSee' being the point which will end up at
  614.         // the bottom of the view, i.e.the minimum amount to be seen and 'rectToReveal'
  615.         // the rect being scrolled.
  616.  
  617.     void RevealTop(Boolean redraw);
  618.         // Scroll the top of a rect into view.
  619.  
  620.     void RevealBottom(Boolean redraw);
  621.         // Scroll the bottom of a rect into view.
  622.  
  623.     virtual void RevealUndoRedo(TCommand* command); // override
  624.         // Make this context visible after undo/redo. 
  625.  
  626.  
  627.     //------------------------------------------------------------------------------------
  628.     // Mouse Handling Methods
  629.     //------------------------------------------------------------------------------------
  630.  
  631.     virtual EventNumber GetEventNumber();
  632.         // Returns cNoEvent. Overridden by TControl.
  633.  
  634.     virtual Boolean ContainsMouse(const VPoint& theMouse);
  635.         // Is the view point 'theMouse' currently in our view.
  636.  
  637.     virtual Boolean HandleMouseDown(const VPoint& theMouse,
  638.                                     TToolboxEvent* event,
  639.                                     CPoint     hysteresis,
  640.                                     EMouseDownType mouseDownType = kDragOrClick);
  641.         // The method responsible for handling a mouse down in the view, calls
  642.         // DoMouseUp to handle it.
  643.  
  644.     virtual Boolean HandleMouseUp(const VPoint& theMouse,
  645.                                   TToolboxEvent* event,
  646.                                   CPoint hysteresis);
  647.         // The method responsible for handling a mouse up in the view, calls
  648.         // DoMouseUp to handle it.
  649.  
  650.     virtual void DoMouseCommand(VPoint& theMouse,
  651.                                 TToolboxEvent* event,
  652.                                 CPoint hysteresis);
  653.         // Posts a simple tracker which by default calls back tracking methods of this
  654.         // view. There are two possibilities here: 1) Override DoMouseCommand to post
  655.         // commands that represent more complex, even undoable actions.That command may
  656.         // either let its tracking call back the view's tracking methods (the default)
  657.         // which must be overridden to do anything useful or it may simply do all the
  658.         // tracking itself. This mostly depends on whether different commands returned
  659.         // from the view would have different tracking behavior.For example this is the
  660.         // approach taken by DrawShapes. 2) Override the view's tracking methods and let
  661.         // the default tracker them.For example this is the approach taken by TControl.
  662.  
  663.     virtual void DoMouseUp(VPoint& theMouse,
  664.                            TToolboxEvent* event,
  665.                            CPoint hysteresis);
  666.         // Called for the most deeply nested view that contains the mouse.
  667.  
  668.     //------------------------------------------------------------------------------------
  669.     // Cursor and Help Handling Methods
  670.     //------------------------------------------------------------------------------------
  671.  
  672.     void RestrictRegionToVisible(RgnHandle aRegion);
  673.         // Restricts the region to the visible extent of this view
  674.         
  675.     virtual Boolean HandlesCursor();
  676.         // Returns true, if this view tracks the mouse so that it can claim the cursor.
  677.         // The default returns true. If false, subviews may still get a chance to set the
  678.         // cursor, as determined by TView::SubViewsHandleCursor.
  679.                 
  680.     virtual Boolean LetsSubViewsHandleCursor();
  681.         // Returns true if this view should allow subviews a chance to set the cursor. If
  682.         // true, the subviews themselves may still return false for HandlesCursor. By
  683.         // setting both values false, cursor tracking can be turned off for an entire
  684.         // window, such as the clipboard window.
  685.  
  686.     virtual Boolean HandlesHelp();
  687.         // Returns true, if this view tracks the mouse so that it can show help. The
  688.         // default returns true. If false, subviews may still get a chance to show help,
  689.         // as determined by TView::SubViewsHandleHelp.
  690.  
  691.     virtual Boolean LetsSubViewsHandleHelp();
  692.         // Returns true if this view should allow subviews a chance to show help. The
  693.         // subviews themselves may still return false for HandlesHelp. By setting both
  694.         // values false, help can be turned off for an entire view hierarchy
  695.     
  696.     void HandleCursor(const VPoint& theMouse, RgnHandle cursorRegion);
  697.         // Try to find a subview that contains the mouse and wants to handle the cursor. 
  698.         // Otherwise, call our behaviors' DoSetCursor method and then our own DoSetCursor
  699.         // method to actually set the cursor. 
  700.  
  701.     void HandleHelp(const VPoint& theMouse, RgnHandle helpRegion);
  702.         // Try to find a subview that contains the mouse and wants to handle the help. 
  703.         // Otherwise, call our own DoShowHelp method to actually show the help balloon. 
  704.         
  705.     virtual void DoSetCursor(const VPoint& localPoint, 
  706.                              RgnHandle cursorRegion);
  707.         // Can be overridden to set the cursor and compute a cursor region. The default
  708.         // sets the cursor to an arrow and uses TView::GetDefaultCursorRegion to compute the
  709.         // largest appropriate cursor region
  710.  
  711.     virtual ResNumber GetHelpID();
  712.         // Returns fHelpID.
  713.         
  714.     virtual short GetHelpIndex();
  715.         // Returns fHelpIndex.
  716.         
  717.     virtual short GetHelpState();
  718.         // Returns kHMEnabledItem, kHMDisabledItem, etc.
  719.         
  720.     virtual ResNumber GetCursorID();
  721.         // Returns fCursorID.
  722.         
  723.     void GetHelpParameters(const VPoint& localPoint,
  724.                            RgnHandle helpRegion,
  725.                            HMMessageRecord& helpMessage,
  726.                            CPoint& localQDTip,
  727.                            CRect& localQDRect,
  728.                            short& balloonVariant);
  729.         // Determine the parameters needed for showing a help balloon for this view. The
  730.         // default calls the TApplication method of the same name which gets the information
  731.         // from a resource of type 'hdlg'. The fields fHelpID and fHelpIndex specify the
  732.         // resource and component within the resource containing the information for this
  733.         // view.
  734.  
  735.     void DoShowBalloon(const VPoint& localPoint,
  736.                        RgnHandle helpRegion,
  737.                        const HMMessageRecord& helpMessage,
  738.                        CPoint localQDTip,
  739.                        const CRect& localQDRect,
  740.                        short balloonVariant);
  741.         // Show the help balloon. 
  742.  
  743.     void DoShowHelp(const VPoint& localPoint, RgnHandle helpRegion);
  744.         // Gets the help parameters and shows the help balloon. 
  745.  
  746.     virtual void GetDefaultCursorRegion(const VPoint& localPoint, 
  747.                                         RgnHandle cursorRegion);
  748.         // Returns the largest appropriate cursor region, called by DoSetCursor.
  749.  
  750.     virtual void GetDefaultHelpRegion(const VPoint& localPoint, RgnHandle helpRegion);
  751.         // Returns the largest appropriate help region, called by DoShowHelp.
  752.  
  753.  
  754.     //------------------------------------------------------------------------------------
  755.     // Miscellaneous Methods
  756.     //------------------------------------------------------------------------------------
  757.  
  758.     virtual TCommandHandler* GetContext(CommandNumber aCommandNumber); // Override
  759.         // Returns the view's document, if any, or the view itself.
  760.  
  761.     virtual GrafPtr GetGrafPort();
  762.         // Returns a pointer to our Graf Port.
  763.  
  764.     virtual TScroller* GetScroller(Boolean immediateSuperView);
  765.         // Returns a reference to our scroller.
  766.  
  767.     virtual TView* GetRootView();
  768.         // Returns a reference to the root view.
  769.  
  770.     virtual TWindow* GetWindow() const;
  771.         // Returns a reference to the window that we are in, if any.
  772.         
  773.     VRect GetExtent() const;
  774.     inline void GetExtent(VRect& itsExtent) const
  775.     { itsExtent = GetExtent(); }
  776.         // Returns a view CRect the size of our extent in 'itsExtent'.
  777.  
  778.     virtual void GetExtentRegion(RgnHandle itsExtentRgn);
  779.         // Shapes the supplied region to the view's extent. Override for non-rectangular
  780.         // views to return a region for the drawable (qdExtent) portion of the view. 
  781.  
  782.     CRect GetQDExtent();
  783.     inline void GetQDExtent(CRect& qdExtent)
  784.     { qdExtent = GetQDExtent(); }
  785.         // Returns a QuickDraw CRect the size of our extent in 'qdExtent'.
  786.  
  787.     VRect GetFrame() const;
  788.     inline void GetFrame(VRect& itsFrame) const
  789.     { itsFrame = GetFrame(); }
  790.         // Returns in'itsFrame' a VRect that is the boundary of our view in superview
  791.         // coordinates. This is calculated by adding its size to its location.
  792.  
  793.     VRect GetVisibleRect();
  794.     inline void GetVisibleRect(VRect& visRect)
  795.     { visRect = GetVisibleRect(); }
  796.         // Returns a CRect enclosing the visible portion of the view in view coordinates.
  797.  
  798.     CRect GetVisibleQDRect();
  799.     inline void GetVisibleQDRect(CRect& visQDRect)
  800.     { visQDRect = GetVisibleQDRect(); }
  801.         // Returns a CRect enclosing the visible portion of the view in QD coordinates.
  802.  
  803.     void GetVisibleRegion(RgnHandle visibleRgn);
  804.         // Returns a visibleRgn enclosing the drawable portion of the view in QD coordinates.
  805.  
  806.     VRect GetDrawableRect();
  807.     inline void GetDrawableRect(VRect& drawRect)
  808.     { drawRect = GetDrawableRect(); }
  809.         // Returns a CRect enclosing the drawable portion of the view in view coordinates.
  810.  
  811.     CRect GetDrawableQDRect();
  812.     inline void GetDrawableQDRect(CRect& drawQDRect)
  813.     { drawQDRect = GetDrawableQDRect(); }
  814.         // Returns a CRect enclosing the drawable portion of the view in QD coordinates.
  815.  
  816.     void GetDrawableRegion(RgnHandle drawRgn);
  817.         // Returns a drawRgn enclosing the drawable portion of the view in view coordinates.
  818.  
  819.     virtual short GetPartCode(const VPoint& theMouse);
  820.         // tells which part of a view, if any, the mouse button was pressed in. Returns:
  821.         // inContent = 3, inDrag = 4, inGrow = 5, inGoAway = 6, or inDesk = 0 (ie. none of
  822.         // the above),depending on where theMouse is in the view
  823.  
  824.     void ViewEnable(Boolean state, Boolean redraw);
  825.         // Enables & Redraws the view based on 'state' & 'redraw'.
  826.  
  827.     virtual void Show(Boolean state, Boolean redraw);
  828.         // If 'state' is not fShown then set fShown to true and call ForceRedraw if
  829.         // 'redraw' is true. Otherwise invalidate our focus and set fShown to 'state'.
  830.  
  831.     virtual Boolean IsShown();
  832.         // Checks to see if our view is currently shown.
  833.  
  834.     Boolean IsVisible();
  835.         // Returns true if any portion of the view is currently visible when focused
  836.  
  837.     Boolean IsDrawable();
  838.         // Returns true if any portion of the view is currently drawable when focused
  839.  
  840.     virtual Boolean IsActive();
  841.         // Returns true if the view is in an "active" superview (typically a window) 
  842.  
  843.     
  844.     //------------------------------------------------------------------------------------
  845.     // Target Management and Validation
  846.     //------------------------------------------------------------------------------------
  847.  
  848.     virtual Boolean WantsToBeTarget();    // Override
  849.         // Returns the value of fWantsToBeTarget
  850.  
  851.     virtual long GetValidationError();
  852.         // Returns an error value "noErr". Overridden by TEditText and TNumberText.
  853.         // Formerly known as "Validate"
  854.         
  855.     Boolean IsValid();
  856.         // Returns true if this view is in a valid state. Calls ValidationFailed
  857.         // if it is not. 
  858.  
  859.     Boolean IsHierarchyValid();
  860.         // Returns true if this view and all its subviews are in a valid state. 
  861.         // User may be alerted via ValidationFailed method.
  862.  
  863.     virtual void ValidationFailed(long reason);
  864.         // Can be overridden to alert the user, as is done by TEditText.
  865.  
  866.     TView* FindTarget();
  867.         // Find a subview which wants to be the target
  868.  
  869.     virtual void SetTargetSelection(Boolean redraw);    // Override
  870.         // Called when this object becomes the target, except as a result of a mouse click
  871.         // Overridden to reveal the view if it is scrolled out of view
  872.  
  873.  
  874.     //------------------------------------------------------------------------------------
  875.     // Clipboard Handling
  876.     //------------------------------------------------------------------------------------
  877.  
  878.     virtual PicHandle AsPict();
  879.         // Returns a PicHandle containing a rendering of the view and its subviews.
  880.  
  881.     virtual Boolean ContainsClipType(ResType aType);
  882.         // Checks to see if the clipboard contains the type 'aType'.
  883.  
  884.     virtual long GivePasteData(Handle aDataHandle, ResType dataType);
  885.         // Gets the scrap data of the type 'dataType', returns any errors as function
  886.         // result.
  887.  
  888.     virtual void WriteToDeskScrap();
  889.         // Writes to desk scrap.
  890.  
  891.  
  892.     //------------------------------------------------------------------------------------
  893.     // PrintingMethods
  894.     //------------------------------------------------------------------------------------
  895.  
  896.     TPrintHandler* GetPrintHandler();
  897.         // return the associated print handler, if any.
  898.  
  899.     void AttachPrintHandler(TPrintHandler* itsPrintHandler);
  900.         // Called by the PrintHandler during its initialization, NOT directly by you
  901.  
  902.     void DetachPrintHandler(TPrintHandler* itsPrintHandler);
  903.         // Called by the PrintHandler when freed, NOT directly by you
  904.  
  905.     virtual VCoordinate DoBreakFollowing(VHSelect vhs,
  906.                                          VCoordinate previousBreak,
  907.                                          Boolean& automatic);
  908.         // Returns the location of the page break which follows the page break located at
  909.         // 'previousBreak', in direction vhs; returns automatic = true if the page-break is
  910.         // thought of as an 'automatic' rather than a 'manual' (user-specified) one. Note
  911.         // that page-breaks in dimension 'v' are drawn as vertical lines, those in
  912.         // dimension 'h' as horizontal lines
  913.  
  914.     virtual VPoint DoCalcPageStrips();
  915.         // Computes the number of horizontal and vertical page strips.
  916.  
  917.     virtual VPoint DoCalcViewPerPage();
  918.         // Determine how much of the view normally goes into each printed page, in each
  919.         // dimension.
  920.  
  921.     virtual void DoCheckPrinter();
  922.         // Check whether printer (if relevant) has changed, and if so, take appropriate
  923.         // action
  924.  
  925.     virtual void DoDrawPrintFeedback(const VRect& area);
  926.         // Draw page-breaks, page-numbers, view-borders, rulers, etc.
  927.  
  928.     virtual void DoDrawPageBreak(VHSelect vhs,
  929.                                  short whichBreak,
  930.                                  VCoordinate loc,
  931.                                  Boolean automatic);
  932.         // Draw one page break.
  933.  
  934.     virtual void DoPagination();
  935.         // Recompute the dividing lines between areas of the view which will be mapped
  936.         // into different printed pages
  937.  
  938.     virtual void DoPrinterChanged();
  939.         // The metrics relating to printer use have changed; absorb the information and
  940.         // react
  941.  
  942.     virtual void DoSetPageOffset(const VPoint& coord);
  943.         // Only reimplement in very unusual circumstances involving Tall-UnAdjusted text
  944.         // printing etc.
  945.  
  946.     virtual VRect GetPrintExtent();
  947.         // Returns the part of the view that is to be printed. The default is to return
  948.         // the view's extent.
  949.  
  950.     virtual void PageInteriorChanged(const VRect& newInterior);
  951.         // Allows a view which is printable to react to the changing of the page-interior
  952.         // rectangle
  953.  
  954.  
  955.     //------------------------------------------------------------------------------------
  956.     // View Tracking Methods
  957.     //------------------------------------------------------------------------------------
  958.  
  959.     virtual void GoAwayByUser(const VPoint& theMouse);
  960.         // Provides tracking for the GoAway box (or other indicator) and calls CloseByUser
  961.         // if go away was indicated.
  962.  
  963.     virtual void MoveByUser(const VPoint& theMouse);
  964.         // Provides tracking for the Title bar (or other drag area) and calls Locate if
  965.         // the location changed.
  966.  
  967.     virtual void ResizeByUser(const VPoint& theMouse);
  968.         // Provides tracking for the Resize box (or other indicator) and calls Resize if
  969.         // the size changed.
  970.  
  971.     virtual void ZoomByUser(const VPoint& theMouse, short partCode);
  972.         // Provides tracking for the Zoom box (or other indicator) and calls Zoom if zoom
  973.         // was indicated.
  974.  
  975.  
  976.     //------------------------------------------------------------------------------------
  977.     // Tracker Tracking Methods
  978.     //------------------------------------------------------------------------------------
  979.  
  980.     virtual Boolean IsDoneTracking();
  981.         // Indicates whether the Tracker is through tracking.(the command is also through
  982.         // tracking if you return NULL from TrackMouse). Defaults to NOT StillDown. Most
  983.         // programs won't have to mess with this. NOTE you still have to deal with queued
  984.         // events if you change the criteria for true.
  985.  
  986.     virtual void TrackConstrain(TrackPhase aTrackPhase,
  987.                                 const VPoint& anchorPoint,
  988.                                 const VPoint& previousPoint,
  989.                                 VPoint& nextPoint,
  990.                                 Boolean mouseDidMove);
  991.         // Override this if your Tracker calls back to the view (the Default) and you want
  992.         // to constrain the mouse point to a grid, force drawing a square, etc. This is
  993.         // called only if fConstrainsMouse is true.
  994.  
  995.     virtual void TrackFeedback(TrackPhase aTrackPhase,
  996.                                const VPoint& anchorPoint,
  997.                                const VPoint& previousPoint,
  998.                                const VPoint& nextPoint,
  999.                                Boolean mouseDidMove,
  1000.                                Boolean turnItOn);
  1001.         // Override this if your Tracker calls back to the view (the Default) and you want
  1002.         // to display any tracking feedback
  1003.  
  1004.     virtual void TrackMouse(TrackPhase aTrackPhase,
  1005.                             VPoint& anchorPoint,
  1006.                             VPoint& previousPoint,
  1007.                             VPoint& nextPoint,
  1008.                             Boolean mouseDidMove);
  1009.         // Override this if your Tracker calls back to the view (the Default) an you want
  1010.         // to display any tracking feedback
  1011.  
  1012.  
  1013.     //------------------------------------------------------------------------------------
  1014.     // View hierarchy management
  1015.     //------------------------------------------------------------------------------------
  1016.     
  1017.     virtual void AddedASubView(TView* newSubView);
  1018.         // Called by AddSubView to notify this view that a subview was added. Calls
  1019.         // fSuperView->AddedASubView so that the notification is passed on to all
  1020.         // superviews
  1021.  
  1022.     virtual void RemovedASubView(TView* theSubView);
  1023.         // Called by RemoveSubView to notify this view that a subview was removed. Calls
  1024.         // fSuperView->RemovedASubView so that the notification is passed on to all
  1025.         // superviews
  1026.  
  1027.     virtual void BeInSuperView(TView* itsSuperView);
  1028.         // Called to notify this view that it has become a subview of theSuperView.
  1029.         // theSuperView can be NULL. Called by TView::AddSubView and TView::RemoveSubView
  1030.  
  1031.     virtual void SetHLPenState(HLState fromHL, HLState toHL);
  1032.         // Set the pen state for highlighting by XOR, given the highlight transition. You
  1033.         // can use this if you use Paint<X> or Frame<X> or line drawing for your
  1034.         // highlighting.
  1035.  
  1036.     //------------------------------------------------------------------------------------
  1037.     // Drag and Drop Methods
  1038.     //------------------------------------------------------------------------------------
  1039.     
  1040. #if qDrag
  1041.     void HandleDragCursor(const VPoint& theMouse, RgnHandle cursorRegion);
  1042.     
  1043.     virtual Boolean DoSetDragCursor(const VPoint& localPoint, 
  1044.                                     RgnHandle cursorRegion,
  1045.                                     RgnHandle& dragCursorRegion);
  1046.         // Can be overridden to set the drag cursor and compute a drag cursor region. 
  1047.         // The default calls DoMakeDragCursorRegion and calls WillDrag, and sets the
  1048.         // cursor to the drag "open hand" if a mouse down would cause a drag. 
  1049.         // dragCursorRegion should be NULL on entry, and must be disposed after calling. 
  1050.  
  1051.     virtual short GetWillDragCursorID();
  1052.         // Get the resource id of the cursor that indicates that the mouse is
  1053.         // over draggable content.
  1054.         
  1055.     virtual short GetIsDraggingCursorID();
  1056.         // Get the resource id of the cursor that indicates that the user is dragging.
  1057.     
  1058.     virtual RgnHandle DoMakeDragCursorRegion();
  1059.         // Create and return a region in local coordinates that can be used
  1060.         // to test whether the mouse is in a location that would initiate a
  1061.         // drag.  This region is also used by DoSetCursor to create a cursor
  1062.         // sleep region
  1063.         
  1064.     virtual Boolean WillDrag(const VPoint& localMouse, const RgnHandle dragCursorRegion);
  1065.         // Returns true if the view wants to drag based on the mouse location
  1066.     
  1067.     virtual TView* DoGetDragProxy();
  1068.         // Dragging view may provide a proxy to manage the drag operation. Not
  1069.         // necessary in most cases.
  1070.         
  1071.     void HandleDrag(TToolboxEvent* event);
  1072.         // Initiate a drag operation
  1073.  
  1074.     virtual void DoAddDragContent();
  1075.         // Add drag items, flavors, and promises to the current drag operation
  1076.  
  1077.     virtual RgnHandle DoMakeDragOutlineRegion();
  1078.         // Create and return a region in local coordinates that can be drawn
  1079.         // to represent data being dragged
  1080.  
  1081.     virtual Boolean WillAcceptDrop(CDragItemIterator& dragItemIterator);
  1082.         // Return true if the view will accept the drop. 
  1083.         
  1084.     virtual void DoDragEnter();
  1085.         // Become the drop target. Set up private data necessary for tracking
  1086.         // the drag within the view.
  1087.         
  1088.     virtual RgnHandle DoMakeDropHiliteRegion();
  1089.         // Create and return a region in local coordinates that can be drawn
  1090.         // to represent that the view is droppable. 
  1091.  
  1092.     virtual void DoDragWithin(const VPoint& localMouse);
  1093.         // update visual drag tracking indication based on the mouse coords.
  1094.                                     
  1095.     virtual void DoDragLeave();
  1096.         // Clean up and remove any view-managed hiliting.
  1097.     
  1098.     virtual Boolean DoMakeDropLocationDescriptor(CAEDesc& dropLocationDesc);
  1099.         // return an AppleEvent descriptor describing the drop location.
  1100.  
  1101.     virtual Boolean WillDragMove(TView *destinationView);
  1102.         // If the drag initiated in this application, return true if data should
  1103.         // be moved instead of copied.
  1104.  
  1105.     virtual TCommand* DoMakeDragDropCommand(CommandNumber itsCommandNumber,
  1106.                                             CDragItemIterator& dragItemIterator);
  1107.         // Create a drag drop command that will be posted by the drag session.
  1108.     
  1109.     virtual void DoFulfillPromise(TDragItem* promisedItem);
  1110.         // Provide data for promised flavors
  1111.         
  1112.     //
  1113.     // If qDrag is false, these accessors will still be around but they won't do
  1114.     // anything. 
  1115.     //
  1116.     inline Boolean GetDraggable() const
  1117.     { return fDraggable; }
  1118.  
  1119.     inline void SetDraggable(Boolean isDraggable)
  1120.     { fDraggable = isDraggable; }
  1121.     
  1122.     inline Boolean GetDroppable() const
  1123.     { return fDroppable; }
  1124.  
  1125.     void SetDroppable(Boolean isDroppable);
  1126.  
  1127.     inline short GetDragMoveDeterminer() const
  1128.     { return fDragMoveDeterminer; }
  1129.     
  1130.     inline void SetDragMoveDeterminer(short dragMoveDeterminer)
  1131.     { fDragMoveDeterminer = dragMoveDeterminer; }
  1132.     
  1133.     inline IDType GetDragMoveFamily() const
  1134.     { return fDragMoveFamily; }
  1135.     
  1136.     inline void SetDragMoveFamily(IDType dragMoveFamily)
  1137.     { fDragMoveFamily = dragMoveFamily; }
  1138. #else
  1139.     inline Boolean GetDraggable() const
  1140.     { return FALSE; }
  1141.  
  1142.     inline void SetDraggable(Boolean /* isDraggable */)
  1143.     {  }
  1144.     
  1145.     inline Boolean GetDroppable() const
  1146.     { return FALSE; }
  1147.  
  1148.     void SetDroppable(Boolean isDroppable);
  1149.  
  1150.     inline short GetDragMoveDeterminer() const
  1151.     { return kNeverMove; }
  1152.     
  1153.     inline void SetDragMoveDeterminer(short /* dragMoveDeterminer */)
  1154.     { }
  1155.     
  1156.     inline IDType GetDragMoveFamily() const
  1157.     { return kNoIdentifier; }
  1158.     
  1159.     inline void SetDragMoveFamily(IDType /* dragMoveFamily */)
  1160.     { }
  1161. #endif // qDrag
  1162.  
  1163.  
  1164. //----------------------------------------------------------------------------------------
  1165. // static functions
  1166. //----------------------------------------------------------------------------------------
  1167. public:
  1168.  
  1169.     static void InitUView(Boolean initGX = TRUE);
  1170.         // Initialize the view system.
  1171.         // if initGX is TRUE then QuickDraw GX will be initialized
  1172.  
  1173.     static void TerminateUView();
  1174.         // Terminate the view system
  1175.  
  1176.     static void GetFocus(FocusRec& theFocusRec);
  1177.         // gets the current focus into a focusrec. The theFocusRec.itsPortInfo.clipRgn must be
  1178.         // a valid rgn.Useful for saving and restoring the focus behind MacApp's back.
  1179.     
  1180.     static void SetFocus(const FocusRec& theFocusRec);
  1181.         // sets the current focus from a focus rec
  1182.     
  1183.     static void GetViewPortInfo(ViewPortInfo& theViewPortInfo);
  1184.         // gets the current PortInfo into a ViewPortInfo. theViewPortInfo.clipRgn must be a
  1185.         // valid rgn.
  1186.     
  1187.     static void SetViewPortInfo(const ViewPortInfo& theViewPortInfo);
  1188.         // sets the current PortInfo from a ViewPortInfo
  1189.     
  1190.     static Boolean IsRectVisible(const CRect& r);
  1191.         // Determine if a CRect is visible in the current grafport.
  1192.     
  1193.     static Boolean IsRectDrawable(const CRect& r);
  1194.         // Determine if any portion of a CRect intersects the ports visRgn AND clipRgn.
  1195.     
  1196.     static void VisibleRect(CRect& rectToRestrict);
  1197.         // trims the supplied CRect down to its intersection with the port's visRgn
  1198.     
  1199.     static void DrawableRect(CRect& rectToRestrict);
  1200.         // trims the supplied CRect down to its intersection with the port's visRgn AND
  1201.         // clipRgn.
  1202.     
  1203.     static void VisibleRgn(RgnHandle rgn);
  1204.         // trims the supplied rgn down to its intersection with the port's visRgn
  1205.     
  1206.     static void DrawableRgn(RgnHandle rgn);
  1207.         // trims the supplied rgn down to its intersection with the port's visRgn AND
  1208.         // clipRgn.
  1209.     
  1210.     static Boolean IsPtVisible(CPoint pt);
  1211.         // Determine if a pt intersects the ports visRgn
  1212.     
  1213.     static Boolean IsPtDrawable(CPoint pt);
  1214.         // Determine if a pt intersects the ports visRgn AND clipRgn.
  1215.     
  1216.     static void PtAndRgn(CPoint aPoint, RgnHandle aRegion);
  1217.         // Adds the given CPoint to the given region
  1218.     
  1219.     static void VRectAndRgn(const VRect& theVRect, RgnHandle theRgn);
  1220.         // Call this procedure to add theVRect to theRgn.
  1221.     
  1222. #if qDebug
  1223.     static void WriteFocus();
  1224.         // Writes information about the current focus to the output
  1225. #endif
  1226.  
  1227.     static RgnHandle GetClipRegion(GrafPtr theGrafPtr);
  1228.         // Return the clipRgn
  1229.  
  1230. //----------------------------------------------------------------------------------------
  1231. // data members
  1232. //----------------------------------------------------------------------------------------
  1233. public:
  1234.     VPoint fLocation;                            // the location in superview coordinates
  1235.  
  1236.     VPoint fSize;                                // the size of this view
  1237.  
  1238.     VPoint fTranslation;                        // translation of coordinates required to
  1239.                                                 // account for the origin of the view's
  1240.                                                 // local coordinate system.
  1241.  
  1242.     VPoint fViewToQDOffset;                        // the computed translation of coordinates
  1243.                                                 // necessary to account for adjustment of
  1244.                                                 // large views down to QD space.
  1245.                                                 // Access only through GetViewToQDOffset!
  1246.  
  1247.     VRect fVisibleExtent;                        // The extent of the view that could be
  1248.                                                 // "visible" through all its superviews
  1249.                                                 // (not taking clipping into account
  1250.                                                 // Access only through GetVisibleExtent!
  1251.  
  1252.     CPoint fQDOrigin;                            // the computed QD origin for the port to
  1253.                                                 // account for the view's location.
  1254.                                                 // Access only through GetQDOrigin!
  1255.  
  1256.     TView* fSuperView;                            // the current superview
  1257.  
  1258.     TView* fSubView;                            // first of subviews of this view (linked list)
  1259.  
  1260.     TView* fNextView;                            // first of siblings of this view (linked list)
  1261.  
  1262.     TDocument* fDocument;                        // the associated document if any.
  1263.  
  1264.     TDrawingEnvironment* fDrawingEnvironment;    // PenSize etc.
  1265.  
  1266.     TAdornerList*  fAdorners;                    // The list of adorners
  1267.  
  1268.     long    fUserArea;                            // assigned from view template for use
  1269.                                                 // by client
  1270.  
  1271.     short    fTemplateVersion;                    // version number of the template used to
  1272.                                                 // instantiate this view
  1273.  
  1274.     short      fHelpIndex;
  1275.  
  1276.     ResNumber fHelpID;
  1277.  
  1278.     ResNumber fCursorID;
  1279.  
  1280.     SizeDeterminer fSizeDeterminer[2];            // how this view's size is to be
  1281.                                                 // determined
  1282.  
  1283.     HLState fActiveHL;                            // the current highlighting state for this 
  1284.                                                 // view in an active window. Typically hlOn.
  1285.     HLState fInactiveHL;                        // the current highlighting state for this 
  1286.                                                 // view in an inactive window. Typically 
  1287.                                                 // hlOff or hlDim
  1288.     
  1289.     Boolean    fHandlesCursor;                        // true if the view tracks the mouse for
  1290.                                                 // cursor setting
  1291.  
  1292.     Boolean    fLetsSubViewsHandleCursor;            // true if subviews should be given a
  1293.                                                 // chance to set the cursor
  1294.  
  1295.     Boolean    fHandlesHelp;                        // true if the view tracks the mouse for
  1296.                                                 // showing help balloons
  1297.                                                 
  1298.     Boolean fHandlesFirstClicks;                // true if the view handles first clicks
  1299.  
  1300.     Boolean    fLetsSubViewsHandleHelp;            // true if subviews should be given a
  1301.                                                 // chance to display help
  1302.  
  1303.     Boolean fShown;                                // is this view to be shown
  1304.  
  1305.     Boolean fWantsToBeTarget;                    // If true, then clicking in this view or tabbing
  1306.                                                 // makes it the target.
  1307.  
  1308.     Boolean fCoordinatesAreInvalid;                // Set true by InvalidateCoordinates
  1309.                                                 // Set false by UpdateCoordinates
  1310.  
  1311. #if qDrag
  1312.   protected:
  1313.     Boolean    fDraggable;                            // can the view be dragged 
  1314.     Boolean    fDroppable;                            // can the view receive drops
  1315.     short    fDragMoveDeterminer;                // defines context for drag move
  1316.     IDType    fDragMoveFamily;                    // defines dragmove family within specified context
  1317. #endif
  1318.  
  1319. //----------------------------------------------------------------------------------------
  1320. // static data members
  1321. //----------------------------------------------------------------------------------------
  1322. public:
  1323.  
  1324.     static TView* gFocusedView;                        
  1325.         // the view that is currently focused
  1326.         
  1327.     static Boolean gPrinting;                        
  1328.         // True if currently Printing
  1329.     
  1330.     static Boolean gDrawingPictScrap;                
  1331.         // True if a view's Draw routine is being called in order to create PICT data in the
  1332.         // Desk Scrap; your View.Draw can check this routine, and insert PictComments as
  1333.         // appropriate if it wishes to have them in the Picture in the Desk Scrap
  1334.       
  1335.     static TView* gDrawingPictScrapView;            
  1336.         // the view being currently drawn in the PICT scrap ??? this stuff is a good candidate
  1337.         // for a small change to the view architecture to more easily allow providing
  1338.         // alternate drawing environments
  1339.  
  1340. #if qGXViews || qGXPrinting    
  1341.     static gxGraphicsClient gGXGraphicsClient;
  1342.         // The main GX Graphic client (when used).
  1343. #endif
  1344. };
  1345.  
  1346. //----------------------------------------------------------------------------------------
  1347. // CSubViewIterator: A simple iterator for subviews.
  1348. //----------------------------------------------------------------------------------------
  1349.  
  1350. class CSubViewIterator
  1351. {
  1352. public:
  1353.     CSubViewIterator(const TView* theSuperView, Boolean itsForward = TRUE);
  1354.  
  1355.     inline Boolean More() const
  1356.     { return fCurrentSubView != NULL; }
  1357.         // Returns true if there are more elements to iterate over
  1358.  
  1359.     void Reset();                    // override
  1360.         // Resets the iterator to begin again
  1361.  
  1362.     inline TView* CurrentSubView() const
  1363.     { return fCurrentSubView; }
  1364.         // returns the current View
  1365.  
  1366.     TView* FirstSubView();
  1367.         // Resets the iterator to begin again and returns the first subview in the subview list
  1368.  
  1369.     TView* NextSubView();
  1370.         // increments and then returns the subview in the subview list
  1371.  
  1372. protected:
  1373.     void Advance();
  1374.         // Advances the iteration
  1375.  
  1376.     inline TView* NextView(TView* aView) const
  1377.     { return aView->fNextView; }
  1378.         // returns the next subview in the subview list
  1379.         
  1380.     TView* PreviousView(TView* aView) const;
  1381.         // returns the previous subview in the subview list
  1382.  
  1383.     inline TView* FirstView() const
  1384.     { return (TView *)fFirstView; }
  1385.         // returns the first subview in the subview list
  1386.         
  1387.     TView* LastView() const;
  1388.         // returns the last subview in the subview list
  1389.  
  1390. private:
  1391.     const TView* fFirstView;
  1392.     TView* fCurrentSubView;
  1393.  
  1394. protected:
  1395.     Boolean fIterateForward;
  1396.     
  1397. };
  1398.  
  1399. //----------------------------------------------------------------------------------------
  1400. // TIncludeView: specialized view which includes another view resource.
  1401. //----------------------------------------------------------------------------------------
  1402.  
  1403. class TIncludeView : public TView
  1404. {
  1405.     MA_DECLARE_CLASS;
  1406.     
  1407. public:
  1408.     //------------------------------------------------------------------------------------
  1409.     // Creation/ Destruction Methods
  1410.     //------------------------------------------------------------------------------------
  1411.  
  1412.     TIncludeView();
  1413.         // Constructor
  1414.     virtual ~TIncludeView();
  1415.         // Destructor
  1416.         
  1417.     void IIncludeView(TDocument* itsDocument,
  1418.                       TView* itsSuperView,
  1419.                       short includeRsrcID,
  1420.                       const VPoint& itsSubViewOffset,
  1421.                       const CStr255& resourceName,
  1422.                       short resourceAttributes);
  1423.  
  1424.     //------------------------------------------------------------------------------------
  1425.     // Standard signature support.
  1426.     //------------------------------------------------------------------------------------
  1427.  
  1428.     virtual IDType GetStandardSignature();    // override 
  1429.         // Returns this class's standard signature.
  1430.  
  1431.     //------------------------------------------------------------------------------------
  1432.     // Stream I/O protocol support.
  1433.     //------------------------------------------------------------------------------------
  1434.  
  1435.     virtual void DoPostCreate(TDocument* itsDocument);
  1436.     
  1437.     virtual void ReadFields(TStream* aStream);
  1438.     
  1439.     virtual void WriteFields(TStream* aStream);
  1440.  
  1441.     virtual void WriteSubViews(TStream* aStream);
  1442.         // don't write any subviews
  1443.  
  1444.     //------------------------------------------------------------------------------------
  1445.     // Frame (Location and Size) Methods
  1446.     //------------------------------------------------------------------------------------
  1447.  
  1448.     virtual void SubViewChangedFrame(TView* theSubView,
  1449.                                      const VRect& oldFrame,
  1450.                                      const VRect& newFrame,
  1451.                                      Boolean invalidate);
  1452.         // Called when one of our subviews changes frame.
  1453.  
  1454. //----------------------------------------------------------------------------------------
  1455. // data members
  1456. //----------------------------------------------------------------------------------------
  1457. public:
  1458.     CStr255    fResourceName;
  1459.     
  1460.     VPoint    fItsSubViewOffset;                    // offset of view in superview
  1461.  
  1462.     short    fIncludeRsrcID;                        // the included view's rsrc id
  1463.  
  1464.     short    fResourceAttributes;
  1465. };
  1466.  
  1467. #endif
  1468.